﻿@using FujiyBlog.Core.DomainObjects
@using FujiyBlog.Core.Extensions

@model FujiyBlog.Web.Areas.Admin.ViewModels.AdminUserSave
@{
    Layout = MVC.Admin.User.Views._Layout;
    bool canEditRoles = (Model.Username != User.Identity.Name && User.IsInRole(Role.EditOtherUsersRoleGroups)) || (Model.Username == User.Identity.Name && User.IsInRole(Role.EditOwnRoleGroups));
}
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>User</legend>
        @Html.HiddenFor(model => model.Id)
        <div class="editor-label">
            @Html.LabelFor(model => model.Username)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Username, new { @readonly = "readonly" })
            @Html.ValidationMessageFor(model => model.Username)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Email)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Email)
            @Html.ValidationMessageFor(model => model.Email)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.DisplayName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DisplayName)
            @Html.ValidationMessageFor(model => model.DisplayName)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.FullName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FullName)
            @Html.ValidationMessageFor(model => model.FullName)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.BirthDate)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.BirthDate)
            @Html.ValidationMessageFor(model => model.BirthDate)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Location)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Location)
            @Html.ValidationMessageFor(model => model.Location)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.SelectedRoleGroups)
        </div>
        <div class="editor-field">
            <ul id="categories-list">
            @foreach (RoleGroup roleGroup in Model.AllRoleGroups)
            {
                <li><input type="checkbox" name="SelectedRoleGroups" value="@roleGroup.Id" @(Model.SelectedRoleGroups.Any(x => x == roleGroup.Id) ? "checked=checked" : string.Empty) @(canEditRoles ? string.Empty : "disabled=disabled")  />@roleGroup.Name</li>
            }
            </ul>
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.About)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.About)
            @Html.ValidationMessageFor(model => model.About)
        </div>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
